package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.et.model.FoodDesk;
import cn.et.model.PageTools;

/**
 * Servlet implementation class TypeServlet
 */
public class TypeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TypeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    FoodDesk fd= new FoodDesk();
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			String name=request.getParameter("typename");
			if(name==null){
				name="";
			}
			String curPage=request.getParameter("curPage");
			Integer curPageInt=1;
			if(curPage!=null && !"".equals(curPage)){
				curPageInt=Integer.parseInt(curPage);
			}
			PageTools lm= fd.getTablePage(name, curPageInt);
			request.setAttribute("lm", lm);
			
			String jsp=request.getParameter("jsp");
			if(jsp==null){
				request.getRequestDispatcher("/detail/cuisineList.jsp").forward(request, response);
			}else if("saveFood".equals(jsp)){
				request.getRequestDispatcher("/detail/saveFood.jsp").forward(request, response);
			}else if("updateFood".equals(jsp)){
				request.getRequestDispatcher("/detail/updateFood.jsp").forward(request, response);
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
